<template>
    <div class="mechanismUser">
        <public-header></public-header>
        <van-search
        @search="getDataInfo"
        v-model="searchvalue"
        shape="round"
        background="#07c160"
        placeholder="请输入搜索关键词"
        />
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh" style="margin-bottom:50px">
            <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
                <van-cell
                v-for="(item,index) in list"
                :key="index"
                :title="item.fusername"
                :value="item.typename"
                />
            </van-list>
        </van-pull-refresh>
    </div>
</template>

<script>
import {
  Button,
  NavBar,
  Icon,
  PullRefresh,
  Toast,
  List,
  SwipeCell,
  Collapse,
  CollapseItem,
  Divider,
  Panel,
  DropdownMenu,
  DropdownItem,
  Search,
  Dialog,
  Cell,
  CellGroup
} from "vant";
import { getRegulatorPerson } from "@/api/gov/mechanismUser";
import publicHeader from "@/components/publicHeader";
export default {
    name: "mechanismUser",
    components: {
        publicHeader,
            [Cell.name]: Cell,
            [CellGroup.name]: CellGroup,
            [NavBar.name]: NavBar,
            [Button.name]: Button,
            [Icon.name]: Icon,
            [PullRefresh.name]: PullRefresh,
            [List.name]: List,
            [SwipeCell.name]: SwipeCell,
            [Collapse.name]: Collapse,
            [CollapseItem.name]: CollapseItem,
            [Divider.name]: Divider,
            [Panel.name]: Panel,
            [DropdownMenu.name]: DropdownMenu,
            [DropdownItem.name]: DropdownItem,
            [Search.name]: Search,
            [Dialog.name]: Dialog,
            [Toast.name]: Toast
    },
    data() {
        return {
            fid: "3647a16c-87c2-43f1-a3d0-60991543216c",
            searchvalue: "",
            list: [],
            loading: false,
            finished: false,
            refreshing: false,
            totalCount: 0,
            pagenumber: 1,
            isLoading: false
        };
    },
    methods: {
        getDataInfo() {
            getRegulatorPerson({
                searchvalue: this.searchvalue,
                fid: this.fid
            }).then(res => {
                this.totalCount = res.pageResult.totalCount;
                this.list = res.pageResult.results;
                this.pagenumber = res.pageResult.pageNo;
                this.loading = false;
                if (this.list.length >= res.pageResult.totalCount) {
                    this.finished = true;
                }
            });
        },
        onRefresh() {
            // 清空列表数据
            this.finished = false;
            // 重新加载数据
            // 将 loading 设置为 true，表示处于加载状态
            this.loading = true;
            this.onLoad();
        },
        onLoad() {
            if (this.isLoading) {
                this.list = [];
                this.isLoading = false;
            }
            getRegulatorPerson({
                searchvalue: this.searchvalue,
                fid: this.fid
            }).then(res => {
                this.totalCount = res.pageResult.totalCount;
                res.pageResult.results.forEach(element => {
                    this.list.push(element);
                });
                this.pagenumber = res.pageResult.pageNo;
                this.loading = false;
                if (this.list.length >= res.pageResult.totalCount) {
                    this.finished = true;
                }
            });
        },
        mesClick(item) {
            console.log(item);
        }
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.mechanismUser .van-cell__title {
  text-align: left;
}
</style>
